﻿namespace Agile.DataAccess.Providers.Common.Builders
{
    internal class ExistsBuilderSqlGenerator
	{
		public string GenerateSql(IDbProvider provider, string parameterPrefix, BuilderData data,string sql)
		{
			var whereSql = "";
			foreach (var column in data.Columns)
			{
				if (whereSql.Length > 0)
					whereSql += " AND ";

				whereSql += string.Format("{0} = {1}{2}",
												provider.EscapeColumnName(column.ColumnName),
												parameterPrefix,
												column.ParameterName);
			}
            return string.Format(sql, data.ObjectName, whereSql);
		}
	}
}
